#define _CRT_SECURE_NO_WARNINGS

#include<string.h>
#include"string.h"
using namespace bit;
#define endl '\n'
using std::cout;
using std::cin;
std::ostream& bit::operator<<(std::ostream& _cout, const bit::string& s)
{

	for (int i = 0; i < s._size; i++)
	{
		_cout << s[i];
	}
	return _cout;
}

std::istream& bit::operator>>(std::istream& _cin, bit::string& s)
{
	s.clear();
	char buff[129] = { 0 };
	char ch = _cin.get();
	int i = 0;
	while (ch != ' ' && ch != '\n')
	{
		buff[i++] = ch;
		if (i == 128)
		{
			buff[i] = '\0';
			s += buff;
			i = 0;
		}
		ch = _cin.get();
	}

	if (i != 0)
	{
		buff[i] = '\0';
		s += buff;
	}
	return _cin;
}

void test_string1()
{
	string s1("hello world");
	cout << s1.c_str() << endl;

	string s2;
	cout << s2.c_str() << endl;

	for (size_t i = 0; i < s1.size(); i++)
	{
		cout << s1[i] << " ";
	}
	cout << endl;

	string::iterator it = s1.begin();
	while (it != s1.end())
	{
		(*it)++;
		cout << *it << " ";
		++it;
	}
	cout << endl;

	for (auto& ch : s1)
	{
		ch++;
		cout << ch << " ";
	}
	cout << endl;

	cout << s1.c_str() << endl;
}

void test_string2()
{
	string s1("hello world");
	cout << s1.c_str() << endl;
	s1.push_back(' ');
	s1.append("hello bit hello bit");

	cout << s1.c_str() << endl;

	s1 += '#';
	s1 += "*********************";
	cout << s1.c_str() << endl;

	string s2;
	s2 += '#';
	s2 += "*********************";
	cout << s2.c_str() << endl;
}

void test_string3()
{
	string s1("hello world");
	cout << s1.c_str() << endl;

	s1.insert(5, '%');
	cout << s1.c_str() << endl;

	s1.insert(s1.size(), '%');
	cout << s1.c_str() << endl;

	s1.insert(0, '%');
	cout << s1.c_str() << endl;
}

void test_string4()
{
	string s1("hello world");
	string s2("hello world");

	cout << (s1 >= s2) << endl;

	s1[0] = 'z';
	cout << (s1 >= s2) << endl;

	cout << s1 << endl;
	cin >> s1;
	cout << s1 << endl;

	/*char ch1, ch2;
	cin >> ch1 >> ch2;*/
}

void test_string5()
{
	string s1("hello world");
	s1.insert(5, "abc");
	cout << s1 << endl;

	s1.insert(0, "xxx");
	cout << s1 << endl;

	s1.erase(0, 3);
	cout << s1 << endl;

	s1.erase(5, 100);
	cout << s1 << endl;

	s1.erase(2);
	cout << s1 << endl;
}

void test_string6()
{
	string s1("hello world");
	cout << s1 << endl;

	s1.resize(5);
	cout << s1 << endl;

	s1.resize(25, 'x');
	cout << s1 << endl;
}



void test_string8()
{
	string s1("hello world");
	string s2 = s1;
	cout << s1 << endl;
	cout << s2 << endl;

	string s3("xxxxxxxxxxxxxxxxxxx");
	s2 = s3;

	cout << s2 << endl;
	cout << s3 << endl;
}

void test_string9()
{
	string s1("hello world");
	cin >> s1;
	cout << s1 << endl;
	cout << s1.size() << endl;
	cout << s1.capacity() << endl;
}






int main()
{
	string s("12");
	s.insert(0, '1');

    std::cout << s << '\n';
    s.erase(0, 2);
    std::cout << s <<'\n';
	test_string1();
	test_string2();
	test_string3();
	test_string4();
	//test_string5();
	test_string6();
	return 0;
}